import grails.test.*

class ProjectTests extends GrailsUnitTestCase {
    protected void setUp() {
        super.setUp()
        mockDomain(Project)
        mockForConstraintsTests(Project)
    }

    protected void tearDown() {
        super.tearDown()
    }

    void testCreateProject() {
        def p = new Project()
        assertFalse p.validate()

        p.name = "SDQI Project"
        assertNotNull(p.name)
        
        p.description = "This project should be finish in time."
        p.startDate = new Date()
        p.endDate = p.startDate + 30
        p.unitPerPhase = 5
        
        assertTrue p.validate()
        assertNotNull p.save()

    }

    void testFindProjects() {
        
        def projects = [
            new Project(name:"SDQI", description: "An Agile Java Project.", startDate: new Date(), endDate: new Date() + 30, unitPerPhase: 5),
            new Project(name:"WAE", description: "An Agile Ruby Project.", startDate: new Date() - 30, endDate: new Date() + 30, unitPerPhase: 10),
            new Project(name:"DSA", description: "An Optional Project.", startDate: new Date() + 10, endDate: new Date() + 20, unitPerPhase: 3)
        ]
        projects*.save(flush:true)

	assertEquals 3, Project.list().size()

        assertNotNull Project.findByName("SDQI")
        assertNotNull Project.findByName("WAE")
        assertNotNull Project.findByName("DSA")
        assertNull Project.findByName("TOC")
    }
}
